package com.spps;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Configuration {
    private String path;

    Configuration(String path) {
        this.path = path;
    }

    String getValue(String key) {
        try {
            // 实例化文档构造器工厂对象
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            // 实例化文档构造器对象
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            // 解析文件
            Document document = documentBuilder.parse(new File(path));
            // 根元素
            Element root = document.getDocumentElement();
            // 节点列表
            NodeList nodeList = root.getElementsByTagName(key);
            // 返回文本内容
            return nodeList.item(0).getTextContent();
        } catch (Exception e) {
        }
        return "";
    }
}
